﻿// Type: System.Object
// Assembly: mscorlib, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
// Assembly location: c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\mscorlib.dll

using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;

namespace System
{
  [ComVisible(true)]
  [ClassInterface(ClassInterfaceType.AutoDual)]
  public class Object
  {
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    public Object()
    {
    }

    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    ~Object()
    {
    }

    public virtual string ToString()
    {
      return this.GetType().ToString();
    }

    public virtual bool Equals(object obj)
    {
      return RuntimeHelpers.Equals(this, obj);
    }

    public static bool Equals(object objA, object objB)
    {
      if (objA == objB)
        return true;
      if (objA == null || objB == null)
        return false;
      else
        return objA.Equals(objB);
    }

    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    public static bool ReferenceEquals(object objA, object objB)
    {
      return objA == objB;
    }

    public virtual int GetHashCode()
    {
      return RuntimeHelpers.GetHashCode(this);
    }

    [SecuritySafeCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public Type GetType();

    [SecuritySafeCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    protected object MemberwiseClone();

    [SecurityCritical]
    private void FieldSetter(string typeName, string fieldName, object val)
    {
      FieldInfo fieldInfo = this.GetFieldInfo(typeName, fieldName);
      if (fieldInfo.IsInitOnly)
        throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));
      Type conversionType = fieldInfo.FieldType;
      if (conversionType.IsByRef)
        conversionType = conversionType.GetElementType();
      if (!conversionType.IsInstanceOfType(val))
        val = Convert.ChangeType(val, conversionType, (IFormatProvider) CultureInfo.InvariantCulture);
      fieldInfo.SetValue(this, val);
    }

    private void FieldGetter(string typeName, string fieldName, ref object val)
    {
      FieldInfo fieldInfo = this.GetFieldInfo(typeName, fieldName);
      val = fieldInfo.GetValue(this);
    }

    private FieldInfo GetFieldInfo(string typeName, string fieldName)
    {
      Type type = this.GetType();
      while (type != null && !type.FullName.Equals(typeName))
        type = type.BaseType;
      if (type == null)
        throw new ArgumentException();
      FieldInfo field = type.GetField(fieldName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
      if (field == null)
        throw new ArgumentException();
      else
        return field;
    }
  }
}
